package com.jomoo.css.common.core.interceptor;

import com.jomoo.css.common.core.constant.CommonConstants;
import com.jomoo.css.common.core.context.ContextHolder;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;

/**
 * @author ling
 * @date 2018/9/14
 */
@Slf4j
public class DefaultFeignInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        if (ContextHolder.getTenantId() == null) {
            log.warn("TTL 中的 租户ID为空，feign拦截器 >> 增强失败");
        }else {
            requestTemplate.header(CommonConstants.TENANT_ID, ContextHolder.getTenantId());
            requestTemplate.header(CommonConstants.REQUEST_GROUP_ID, ContextHolder.getSid());
            requestTemplate.header(CommonConstants.REQUEST_REMOTE_IP, ContextHolder.getRemoteIp());
        }
    }
}
